<?php

declare(strict_types=1);
/**
 * 权限验证
 * Author: Zane
 * Email: 873934580@qq.com
 * Date: 2023/5/26.
 */

namespace App\Http\Middleware;

use App\Exceptions\CommonExceptionConstants;
use App\Exceptions\ServiceException;
use Illuminate\Support\Facades\Auth;

class Permission
{
    public function handle($request, \Closure $next, ...$guards)
    {
        $guards = empty($guards) ? [config('auth.default.guard')] : $guards;
        foreach ($guards as $guard) {
            if (!Auth::guard($guard)->check()) {
                throw new ServiceException(CommonExceptionConstants::NO_LOGIN);
            }
        }

        return $next($request);
    }
}
